package com.gl.library.widget.onclicklistener;

import android.view.View;

import java.util.Calendar;

public abstract class OnClickFastListener implements View.OnClickListener {

	// 防止快速点击默认等待时长为500ms
	private static final int DEFAULT_DELAY_TIME = 2300;
	private long mDelayTime;
	private static long lastClickTime;
	private int position;

	public OnClickFastListener(long delayTime) {
		this.mDelayTime = delayTime;
	}

	public OnClickFastListener() {
		this.mDelayTime = DEFAULT_DELAY_TIME;
	}

	public OnClickFastListener(int position) {
		this.position = position;
	}

	@Override
	public void onClick(View v) {
		// 判断当前点击事件与前一次点击事件时间间隔是否小于阙值
		long currentTime = Calendar.getInstance().getTimeInMillis();
		if (currentTime - lastClickTime > mDelayTime) {
			lastClickTime = currentTime;
			onFastClick(v);
		}
	}

	/**
	 * 快速点击事件回调方法
	 * @param v
	 */
	public abstract void onFastClick(View v);
}